package good

import (
	"api/internal/respons"
	"api/internal/svc"
	"api/internal/types"
	"context"
	"homepage_srv/homepageclient"

	"github.com/zeromicro/go-zero/core/logx"
)

type GoodCreateSKULogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewGoodCreateSKULogic(ctx context.Context, svcCtx *svc.ServiceContext) *GoodCreateSKULogic {
	return &GoodCreateSKULogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

// 商品SKU添加
func (l *GoodCreateSKULogic) GoodCreateSKU(req *types.GoodCreateSKURequest) (resp *types.Response, err error) {
	goodSKU, err := l.svcCtx.HomepageGrpc.GoodCreateSKU(l.ctx, &homepageclient.GoodCreateSKURequest{
		GoodId: uint64(req.GoodId),
		Color:  req.Color,
		Stock:  uint64(req.Stock),
		Sales:  uint64(req.Sales),
		Price:  float32(req.Price),
		Image:  req.Image,
		Weight: float32(req.Weight),
		Volume: float32(req.Volume),
	})
	if err != nil {
		return respons.Error(400, "服务端错误", err.Error()), err
	}

	return respons.Success(goodSKU), nil
}
